package com.xjj.recursion;

import java.util.ArrayList;
import java.util.List;

public class M0078Subsets {

    private final List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        getSub(nums, 0, new ArrayList<>());
        return result;
    }

    private void getSub(int[] nums, int index, List<Integer> tmp) {
        if (index == nums.length) {
            result.add(new ArrayList<>(tmp));
            return;
        }
        // 不加上此时index的值
        getSub(nums, index + 1, tmp);

        // 加上此时index的值
        tmp.add(nums[index]);
        getSub(nums, index + 1, tmp);
        // tmp还原此时未加的状态
        tmp.remove(tmp.size() - 1);
    }
}
